package com.ibuonline.search.solr.extend;

import java.lang.reflect.InvocationTargetException;
import java.util.Map;

import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Required;

import com.ibuonline.search.solr.extend.model.Company;
import com.ibuonline.search.solr.extend.service.CompanyManager;

public class CompanyExternalDataHandler extends AbstractExternalDataHandler<Company> {
	private CompanyManager companyManager;

	@Override
	protected void saveExternalData(Company company) {
		companyManager.saveCompany(company);
	}

	@Override
	protected void deleteExternalData(Object id) {
		if (id instanceof String) {
			id = Long.parseLong((String) id);
		}
		this.companyManager.deleteCompany((Long) id);
	}

	@Override
	protected Company toModel(Map<String, Object> props) {
		Company prod = new Company();
		try {
			BeanUtils.populate(prod, props);
		} catch (IllegalAccessException e) {
		} catch (InvocationTargetException e) {
		}
		return null;
	}

	/**
	 * @param companyManager
	 *            the companyManager to set
	 */
	@Required
	public void setCompanyManager(CompanyManager companyManager) {
		this.companyManager = companyManager;
	}

}
